<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="text">
<input type="button" value="平方" onclick="square()">
<h1>结果：<span></span></h1>

<script>

  let x = document.querySelector("input");
  let y = document.querySelector("span");
  function square(){
    if (isNaN(x.value)) {
      y.innerText = "输入错误";
      return;
    }
    // y.innerText = x.value * x.value;
    //字符串进行减乘除时会自动转成数值，加法运算时拼接
    // y.innerText = x.value + x.value;
    //parseFloat(字符串)：将字符串转成整数或小数
    //y.innerText = parseFloat(x.value)+parseFloat(x.value);
    y.innerText = x.value*1+x.value*1;
  }
</script>
</body>
</html>